package com.raccoonagents.tools.cascet2d.model.stage;

import com.raccoonagents.tools.cascet2d.interfaces.IGraphicContainer;
import com.raccoonagents.tools.cascet2d.interfaces.IRenderableStageElement;
import com.raccoonagents.tools.cascet2d.interfaces.IStageLocker;
import com.raccoonagents.tools.cascet2d.interfaces.IUpdateable;
import com.raccoonagents.tools.cascet2d.interfaces.rendering.IRenderableObject;
import com.raccoonagents.tools.cascet2d.interfaces.rendering.IWindow;
import com.raccoonagents.tools.cascet2d.model.MainApp;
import com.raccoonagents.tools.cascet2d.model.Vector2f;
import com.raccoonagents.tools.cascet2d.model.containers.AbstractGraphicContainerElement;

public class PlainWindow extends AbstractGraphicContainerElement implements IWindow, IRenderableObject, IStageLocker{
		protected boolean visible;
		protected boolean pauseStage;
		/**
		 * 
		 * @param parent
		 * @param size
		 * @param location
		 * @param pauseStage
		 */
		public PlainWindow(final IGraphicContainer parent,final Vector2f size, final Vector2f location){
			super(parent, size, location);
			this.size = size;
		}
		
		@Override
		public float getOpacity() {
			return 1.0f;
		}

		
		@Override
		public void render() {
			if(!visible){
				return;
			}		
			super.render();				
		}

		@Override
		public void close() {
			visible = false;
			if(pauseStage){
				MainApp.getCurrentStage().releaseLock();
			}
		}

		
		@Override
		public void setVisible() {
			visible = true;
			if(pauseStage){
				MainApp.getCurrentStage().lock(this);
			}
			
		}

		
		
		
		@Override
		public void update() {
			super.update();
			if(!visible){
				return;
			}		
		}

		@Override
		public float[] getColor() {
			return new float []{1.0f,1.0f,1.0f};
		}
		


		@Override
		public float getRotation() {
			return 0;
		}


		@Override
		public Vector2f getSize() {
			return size;
		}



		@Override
		public void updateLock() {
			update();
			for(final IRenderableStageElement elem : getChildren()){
				if(elem instanceof IUpdateable){
					((IUpdateable)elem).update();
				}
			}
		}

		@Override
		public void setIsLocking(final boolean lock) {
			this.pauseStage = lock;			
		}

		

}

